package com.tz.tzgw.pc.web.dao;

import com.alibaba.fastjson.JSON;
import com.tz.tzgw.pc.web.model.Site;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class SiteDao {
    private final JdbcTemplate jdbcTemplate;

    public SiteDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public Site getInfo() {
        String sql = "SELECT * FROM tz_site WHERE id = 1";
        List<Site> result = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Site.class));
        if (result.isEmpty()) {
            return null; // 或者执行其他相应的逻辑
        } else {
            return result.get(0);
        }
    }

    public int updateSite(Site site) {
        String sql = "UPDATE tz_site SET title = ?, sub_title = ?, logo = ?, keyword = ?, content = ?, beian = ?, tongji = ?, bottom_info = ? WHERE id = 1";
        int result = jdbcTemplate.update(sql, site.getTitle(), site.getSub_title(), site.getLogo(), site.getKeyword(), site.getContent(), site.getBeian(), site.getTongji(), site.getBottom_info());
        return result;
    }
}
